package com.com.knowledgepaymentmanagementsystem.controller.course;

import com.com.knowledgepaymentmanagementsystem.pojo.course.Column;
import com.com.knowledgepaymentmanagementsystem.service.course.ColumnService;
import com.com.knowledgepaymentmanagementsystem.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: TODO
 * @author: FY
 * @date: 2025/9/22 15:42
 * @version: JDK 8
 **/
@RestController
@CrossOrigin
@Api(tags = "课程专栏")
@RequestMapping("/column")
public class ColumnController {
    @Autowired
    private ColumnService columnService;

    @ApiOperation(value = "查询课程专栏",httpMethod = "POST",notes = "查询课程专栏")
    @PostMapping("/find")
    public ResultUtil<List<Column>> getColumns(@RequestBody Column column){
        try {
            List<Column> columns = columnService.getColumn(column);
            return new  ResultUtil<>(200,"查询成功",columns);
        } catch (Exception e) {
            e.printStackTrace();
            return new  ResultUtil<>(500,"查询失败");
        }
    }
    @ApiOperation(value = "新增课程专栏",httpMethod = "POST",notes = "新增课程专栏")
    @PostMapping("/insert")
    public ResultUtil insertColumns(@RequestBody Column column){
        try {
            int affected = columnService.insertColumns(column);
            return new ResultUtil<>(200,"新增成功",affected);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"新增失败");
        }
    }

    @ApiOperation(value = "修改课程专栏",httpMethod = "PUT",notes = "修改课程专栏")
    @PutMapping("/update")
    public ResultUtil updateLives(@RequestBody Column column){
        try {
            columnService.updateColumns(column);
            return new ResultUtil(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"修改失败");
        }
    }

    @ApiOperation(value = "删除课程专栏",httpMethod = "DELETE",notes = "删除课程专栏")
    @DeleteMapping("/delete")
    public ResultUtil deleteColumns(@RequestParam("id") Integer id){
        try {
            columnService.deleteColumns(id);
            return new ResultUtil(200,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"删除失败");
        }
    }

}
